package com.zxs.test.service;

import java.util.*;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jayway.jsonpath.Criteria;
import com.zxs.test.dev.dao.gen.AdminuserMapper;
import com.zxs.test.dev.model.gen.Adminuser;
import com.zxs.test.dev.model.gen.AdminuserExample;

@Service
public class UserService {
	@Autowired
	private AdminuserMapper mapper;
	public List<Adminuser>getAllUser(){
		Map<String, Object> map = new HashMap<String,Object>();
		AdminuserExample example = new AdminuserExample();
	    example.createCriteria();
	    List<Adminuser> list=this.mapper.selectByExample(example);
		return list;
	}
	
	public int updateUser(Adminuser user) {
		if(user!=null) {
			return this.mapper.updateByPrimaryKey(user);
		}else {
			return -1;
		}
		
	}
	
	public int insertUser(Adminuser adminuser) {
		if(adminuser!=null) {
			return this.mapper.insert(adminuser);
		}
		else {
			return -1;
		}
	}
	
	public int deleteUser(int id) {
		if(id<1)
		{
			return -1;
		}else {
			return this.mapper.deleteByPrimaryKey(id);
		}	
	}
	public int deleteUserByExample() {
		AdminuserExample aExample = new AdminuserExample();
		//Criteria criteria = new AdminuserExample().createCriteria();
		aExample.createCriteria().andIdGreaterThan(6).andUseridEqualTo("admin7");
		return this.mapper.deleteByExample(aExample);
	}
}
